<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Account Helper
 *
 * @package     VisualQ Local System
 * @author      CSU OJT Students '10 - '11
 * @copyright   Copyright (c) 2010 - 2011, Bitstop Network Services, Inc.
 * @version     0.1b January 09, 2011
 */

if( ! function_exists('check_active_account'))
{
    /*
     * Checks if the active account matches the given criteria and redirects the user to the correct controller
     *
     * @access  public
     * @param   array
     */
    function check_active_account($params)
    {
        // Checks if there is an active account
        if($params['id'])
        {
            // Checks if the given criteria is 'manager'
            if(strcmp($params['controller'], 'manager') == 0)
            {
                // Checks if the account type of the active account is NOT 'manager'
                if( ! strcmp($params['type'], 'manager') == 0)
                {
                    redirect(base_url());
                }
            }
            // Checks if the given criteria is 'agent'
            if(strcmp($params['controller'], 'agent') == 0)
            {
                // Checks if the account type of the active account is NOT 'agent'
                if( ! strcmp($params['type'], 'agent') == 0)
                {
                    redirect(base_url());
                }
            }
            // Checks if the given criteria is 'login'
            if(strcmp($params['controller'], 'login') == 0)
            {
                // Checks if the account type of the active account is 'manager'
                if(strcmp($params['type'], 'manager') == 0)
                {
                    redirect(base_url() . 'manager/');
                }
                // Checks if the account type of the active account is 'agent'
                if(strcmp($params['type'], 'agent') == 0)
                {
                    redirect(base_url() . 'agent/');
                }
            }
        }
        else
        {
            // Checks if the given criteria is NOT 'login'
            if( ! strcmp($params['controller'], 'login') == 0)
            {
                redirect(base_url());
            }
        }
    }
}

/* End of file account_helper.php */
/* Location: ./system/application/controllers/account_helper.php */